﻿using HZ.Public;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HZ.PublicDispatch
{
    public class CallWCSClass
    {
        private static PalletSrv.JshInterfaceForTraySoapClient palletClient = null;
        private static WarehouseSrv.JshInterfaceForFormSoapClient warehouseClient = null;
        private static string strPalletSrvUri = "";
        private static string strWarehouseSrvUri = "";
        private static string sNames = "Form";//”Form”表示化成，”AG”或其他表示分容

/*        public static WarehouseSrv.FormListDataRsp GetListFormByAllTest()
        {
            palletClient = new PalletSrv.JshInterfaceForTraySoapClient();
            warehouseClient = new WarehouseSrv.JshInterfaceForFormSoapClient();
            WarehouseSrv.FormListDataRsp data = warehouseClient.GetListFormByAll(sNames);           
            return data;
        }*/

        public static bool InitPalletSrv()
        {
            try
            {
                if (palletClient == null)
                {
                    palletClient = new PalletSrv.JshInterfaceForTraySoapClient();
                    if (!string.IsNullOrWhiteSpace(strPalletSrvUri))
                        palletClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(strPalletSrvUri);
                }

                if (PublicClass.projectConfig.system.DeviceType == 1)//0化成 1分容 2DCIR
                    sNames = "AG";
                if (PublicClass.projectConfig.system.DeviceType == 2)//0化成 1分容 2DCIR
                    sNames = "DCIR";
                return true;
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("托盘信息接口初始化失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.InitPalletSrv:" + ee.Message);
                return false;
            }
        }

        public static bool InitWarehouseSrv()
        {
            try
            {
                if (warehouseClient == null)
                {
                    warehouseClient = new WarehouseSrv.JshInterfaceForFormSoapClient();
                    if (!string.IsNullOrWhiteSpace(strWarehouseSrvUri))
                        warehouseClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(strWarehouseSrvUri);
                }
                return true;
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("库位取放接口初始化失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.InitWarehouseSrv:" + ee.Message);
                return false;
            }
        }

        /// <summary>
        /// OCV&&DCR测试结束
        /// </summary>
        /// <param name="sOperation">表示操作(DCR为TSDCIR)</param>
        /// <param name="sTrayCode">托盘条码</param>
        /// <returns></returns>
        public static PalletSrv.MsgRsp SetOCV_DCRTestEnd(string sOperation, string sTrayCode)
        {
            PalletSrv.MsgRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctSetOCV_DCRTestEnd(sOperation, sTrayCode);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.SetOCV_DCRTestEnd(" + sOperation + "," + sTrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.SetOCV_DCRTestEnd(" + sOperation + "," + sTrayCode + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.SetOCV_DCRTestEnd(" + sOperation + "," + sTrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.SetOCV_DCRTestEnd(" + sOperation + "," + sTrayCode + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 获取所有工序对应的状态
        /// </summary>
        /// <returns></returns>
        public static PalletSrv.ctMsgRspGetOPeration GetOperation()
        {
            PalletSrv.ctMsgRspGetOPeration data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctGetOperation();
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetOperation调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetOperationd调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetOperation调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetOperation调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 获取电芯条码
        /// </summary>
        /// <param name="strPalletNo">托盘编号</param>
        /// <returns></returns>
        public static async Task<PalletSrv.ctTrayDataRsp> GetTrayInfo_Async(string strPalletNo)
        {
            PalletSrv.ctTrayDataRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = await palletClient.ctGetTrayDatasAsync(strPalletNo);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetTrayInfo_Async(" + strPalletNo + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetTrayInfo_Async(" + strPalletNo + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetTrayInfo_Async(" + strPalletNo + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetTrayInfo_Async(" + strPalletNo + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 获取托盘的详细信息
        /// </summary>
        /// <param name="sTrayCode">托盘条码</param>
        /// <returns></returns>
        public static PalletSrv.ctTrayDataRsp GetTrayInfo(string sTrayCode)
        {
            PalletSrv.ctTrayDataRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctGetTrayDatas(sTrayCode);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetTrayInfo(" + sTrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetTrayInfo(" + sTrayCode + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetTrayInfo(" + sTrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetTrayInfo(" + sTrayCode + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 化成容量DCR测试结果上传
        /// </summary>
        /// <param name="sOperation">表示当前操作（化成_FORMN，容量AG_CAPAC1,容量DG_CAPAC6,DCIR_TSDCIR）</param>
        /// <param name="Battcodes">电芯条码</param>
        /// <param name="sResult">测试结果</param>
        /// <param name="sData">测试数据</param>
        /// <returns></returns>
        public static PalletSrv.MsgRsp SetFormAGBDGDCIRTestResult(string sOperation, string[] Battcodes, int[] sResult, string[] sData)
        {
            PalletSrv.MsgRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctSetFormAGBDGDCIRTestResult(sOperation, Battcodes, sResult, sData);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.SetFormAGBDGDCIRTestResult(" + sOperation + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.SetFormAGBDGDCIRTestResult(" + sOperation + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.SetFormAGBDGDCIRTestResult(" + sOperation + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.SetFormAGBDGDCIRTestResult(" + sOperation + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 化成容量测试结束
        /// </summary>
        /// <param name="sOperation">表示当前操作（化成_FORMN，容量AG_CAPAC1,容量DG_CAPAC6,DCIR_TSDCIR）</param>
        /// <param name="TrayCode">托盘编号</param>
        /// <param name="EndTime">化成容量结束时间</param>
        /// <returns></returns>
        public static PalletSrv.MsgRsp SetFormAGDGTestEnd(string sOperation, string TrayCode, DateTime EndTime)
        {
            PalletSrv.MsgRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctSetFormAGDGTestEnd(sOperation, TrayCode, EndTime);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.SetFormAGDGTestEnd(" + sOperation + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.SetFormAGDGTestEnd(" + sOperation + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.SetFormAGDGTestEnd(" + sOperation + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.SetFormAGDGTestEnd(" + sOperation + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 化成容量测试开始
        /// </summary>
        /// <param name="sOperation">表示当前操作（化成_FORMN，容量AG_CAPAC1,容量DG_CAPAC6,DCIR_TSDCIR）</param>
        /// <param name="TrayCode">托盘编号</param>
        /// <param name="workshopID">???</param>
        /// <param name="LocationID">表示位置(库位编号)</param>
        /// <param name="StartTime">化成容量开始时间</param>
        /// <returns></returns>
        public static PalletSrv.MsgRsp SetFormAGDGTestStart(string sOperation, string TrayCode, string workshopID, string LocationID, DateTime StartTime)
        {
            PalletSrv.MsgRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctSetFormAGDGTestStart(sOperation, TrayCode, workshopID, LocationID, StartTime);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.SetFormAGDGTestStart(" + sOperation + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.SetFormAGDGTestStart(" + sOperation + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.SetFormAGDGTestStart(" + sOperation + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.SetFormAGDGTestStart(" + sOperation + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 获取整盘电芯的测试结果
        /// </summary>
        /// <param name="sTrayCode">托盘条码</param>
        /// <returns></returns>
        public static PalletSrv.ctMsgRspResult GetTestResultOperationAll(string sTrayCode)
        {
            PalletSrv.ctMsgRspResult data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctGetTestResultOperationAll(sTrayCode);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetTestResultOperationAll(" + sTrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetTestResultOperationAll(" + sTrayCode + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetTestResultOperationAll(" + sTrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetTestResultOperationAll(" + sTrayCode + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 获取单电芯的测试结果
        /// </summary>
        /// <param name="sBattCode">电芯条码</param>
        /// <returns></returns>
        public static PalletSrv.ctMsgRspResult GetTestResultOperationOne(string sBattCode)
        { 
            PalletSrv.ctMsgRspResult data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctGetTestResultOperationOne(sBattCode);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetTestResultOperationOne(" + sBattCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetTestResultOperationOne(" + sBattCode + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetTestResultOperationOne(" + sBattCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetTestResultOperationOne(" + sBattCode + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 托盘状态跳转
        /// </summary>
        /// <param name="TrayCode">托盘条码</param>
        /// <param name="sOperation">操作</param>
        /// <returns></returns>
        public static PalletSrv.MsgRsp SetTrayStatus(string TrayCode,string sOperation)
        {
            PalletSrv.MsgRsp data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctSetTrayStatus(TrayCode, sOperation);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.SetTrayStatus(" + TrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.SetTrayStatus(" + TrayCode + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.SetTrayStatus(" + TrayCode + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.SetTrayStatus(" + TrayCode + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 获取电芯所处状态
        /// </summary>
        /// <param name="sBattery">电芯条码</param>
        /// <returns></returns>
        public static PalletSrv.ctMsgRspBattStatus GetkBattCodeStatus(string sBattery)
        {
            PalletSrv.ctMsgRspBattStatus data = null;
            try
            {
                if (palletClient != null)
                {
                    data = palletClient.ctGetkBattCodeStatus(sBattery);
                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.SetTrayStatus(" + sBattery + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.SetTrayStatus(" + sBattery + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.SetTrayStatus(" + sBattery + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.SetTrayStatus(" + sBattery + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 获取所有库位在调度系统中的状态
        /// </summary>
        /// <returns></returns>
        public static async Task<WarehouseSrv.FormListDataRsp> GetListFormByAll_Async(string sNames)
        {
            WarehouseSrv.FormListDataRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = await warehouseClient.GetListFormByAllAsync(sNames);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetListFormByAll_Async()调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetListFormByAll_Async()调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetListFormByAll_Async()调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetListFormByAll_Async()调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// GetListFormByAll调用失败，只记录一次就不再记录日志，否则没有MES的时候，错误日志就太多了
        /// 0 未初始化  1 上一次调用成功  上一次调用失败
        /// </summary>
        private static int nGetListFormByAll_WriteLog= 0;

        /// <summary>
        /// 获取所有库位在调度系统中的状态
        /// </summary>
        /// <returns></returns>
        public static WarehouseSrv.FormListDataRsp GetListFormByAll()
        {
            WarehouseSrv.FormListDataRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.GetListFormByAll(sNames);

                    if (!data.result)
                    {
                        if (nGetListFormByAll_WriteLog==0 || nGetListFormByAll_WriteLog==1)//第一次初始化  或者 上一次是成功
                        {
                            PublicClass.WriteLog2DB("CallWCSClass.GetListFormByAll()调用失败", PublicClass.LogContentType.Dispatcher);
                            PublicClass.WriteLog("CallWCSClass.GetListFormByAll()调用失败：" + data.msg);

                            nGetListFormByAll_WriteLog = 2;
                        }
                    }
                    else
                    {
                        if(nGetListFormByAll_WriteLog==0 || nGetListFormByAll_WriteLog == 2)//第一次初始化  或者 上一次是失败
                            PublicClass.WriteLog2DB("CallWCSClass.GetListFormByAll()调用成功", PublicClass.LogContentType.Dispatcher);

                        nGetListFormByAll_WriteLog = 1;
                    }
                }
            }
            catch (Exception ee)
            {
                if (nGetListFormByAll_WriteLog == 0 || nGetListFormByAll_WriteLog == 1)//第一次初始化  或者 上一次是成功
                {
                    PublicClass.WriteLog2DB("CallWCSClass.GetListFormByAll()调用失败", PublicClass.LogContentType.Dispatcher);
                    PublicClass.WriteLog("CallWCSClass.GetListFormByAll()调用失败：" + ee.Message);

                    nGetListFormByAll_WriteLog = 2;
                }
            }

            return data;
        }

        /// <summary>
        /// 获取指定库位在调度系统中的状态
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <returns></returns>
        public static async Task<WarehouseSrv.FormDataRsp> GetListFormByID_Async(int id)
        {
            WarehouseSrv.FormDataRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = await warehouseClient.GetListFormByIDAsync(sNames, id);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetListFormByID_Async(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetListFormByID_Async(" + id + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetListFormByID_Async(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetListFormByID_Async(" + id + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 获取指定库位在调度系统中的状态
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <returns></returns>
        public static WarehouseSrv.FormDataRsp GetListFormByID(int id)
        {
            WarehouseSrv.FormDataRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.GetListFormByID(sNames,id);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.GetListFormByID(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.GetListFormByID(" + id + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.GetListFormByID(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.GetListFormByID" + id + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应库位门禁信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0 OK，门前RGV可通行，1 门打开，门前RGV不可以通过</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateDoorInduction(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateDoorInduction(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateDoorInduction(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateDoorInduction(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateDoorInduction(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateDoorInduction(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }


        /// <summary>
        /// 更新对应id库位报警信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="strVal">strVal表示报警内容（无报警需要将此字段至空）</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateMacAlarm(int id, string strVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateMacAlarm(sNames, id, strVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateMacAlarm(" + id + "," + strVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateMacAlarm(" + id + "," + strVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateMacAlarm(" + id + "," + strVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateMacAlarm(" + id + "," + strVal + ")调用失败：" + ee.Message);

            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位与调度应答信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">表示对应回复的应答值（调度取放流程中有详细说明）</param>
        /// <returns></returns>
        public static async Task<WarehouseSrv.MsgRsp> UpdateGetPutAns_Async(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = await warehouseClient.UpdateGetPutAnsAsync(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateGetPutAns_Async(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateGetPutAns_Async(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateGetPutAns_Async(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateGetPutAns_Async(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位与调度应答信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">表示对应回复的应答值（调度取放流程中有详细说明）</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateGetPutAns(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateGetPutAns(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateGetPutAns(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateGetPutAns(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateGetPutAns(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateGetPutAns(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位禁用启用信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0启用，1禁取，2禁放，3不可取放</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateManualAuto(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateManualAuto(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateManualAuto(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateManualAuto(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateManualAuto(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateManualAuto(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位状态信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0未知，1可取，2可放，3工作中</param>
        /// <returns></returns>
        public static async Task<WarehouseSrv.MsgRsp> UpdateFloorStatus_Async(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = await warehouseClient.UpdateFloorStatusAsync(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateFloorStatus_Async(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateFloorStatus_Async(" + id + "," + iVal + ")调用失败：" + data.msg);

                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateFloorStatus_Async(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateFloorStatus_Async(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位状态信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0未知，1可取，2可放，3工作中</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateFloorStatus(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateFloorStatus(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateFloorStatus(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateFloorStatus(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateFloorStatus(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateFloorStatus(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }


        /// <summary>
        /// 更新对应id库位化成启动
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0初始，1启动请求</param>
        /// <returns></returns>
        public static async Task<WarehouseSrv.MsgRsp> UpdateStartMac_Async(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = await warehouseClient.UpdateStartMacAsync(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateStartMac_Async(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateStartMac_Async(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateStartMac_Async(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateStartMac_Async(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位化成启动
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0初始，1启动请求</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateStartMac(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateStartMac(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateStartMac(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateStartMac(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateStartMac(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateStartMac(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 库位心跳
        /// </summary>
        /// <param name="sysName">sysName表示对应库位的设备名称，以单机软件命名，用于调度识别设备是否在线</param>
        /// <returns></returns>
        public static async Task<WarehouseSrv.MsgRsp> UpdateSysLive_Async(string sysName)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = await warehouseClient.UpdateSysLiveAsync(sNames, sysName);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateSysLive_Async(" + sysName + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateSysLive_Async(" + sysName + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateSysLive_Async(" + sysName + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateSysLive_Async(" + sysName + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 库位心跳
        /// </summary>
        /// <param name="sysName">sysName表示对应库位的设备名称，以单机软件命名，用于调度识别设备是否在线</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateSysLive(string sysName)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateSysLive(sNames, sysName);

                    if (!data.result)
                    {
                        //PublicClass.WriteLog2DB("CallWCSClass.UpdateSysLive(" + sysName + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        //PublicClass.WriteLog("CallWCSClass.UpdateSysLive(" + sysName + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateSysLive(" + sysName + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateSysLive(" + sysName + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应id库位烟雾报警信息
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">0 无   1表示有报警</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateNeedleBedSmoke(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateNeedleBedSmoke(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateNeedleBedSmoke(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateNeedleBedSmoke(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateNeedleBedSmoke(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateNeedleBedSmoke(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应库位的要料模式
        /// 在设备空闲，到达对应工装的校准时间，请求放料前调用
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iVal">1表示要正常料，70-89表示对应的工装</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateFormGetPutType(int id, int iVal)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateFormGetPutType(sNames, id, iVal);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateFormGetPutType(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateFormGetPutType(" + id + "," + iVal + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateFormGetPutType(" + id + "," + iVal + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateFormGetPutType(" + id + "," + iVal + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 更新对应库位的校准结果
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <param name="iLoadStatus">工装类型（盘状态）</param>
        /// <param name="sCheckoutTime">校准完成时间</param>
        /// <param name="sCheckoutResult">校准结果（OK/NG）</param>
        /// <param name="sCheckoutResultData">校准数据,多通道数据以英文逗号隔开</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateFormEquipResult(int id, int iLoadStatus, string sCheckoutTime, string sCheckoutResult, string sCheckoutResultData)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateFormEquipResult(sNames, id, iLoadStatus, sCheckoutTime, sCheckoutResult, sCheckoutResultData);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.pdateFormEquipResult(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.pdateFormEquipResult(" + id + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.pdateFormEquipResult(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.pdateFormEquipResult(" + id + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 异常换库
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateErrTrayChangePlaces(int id)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateErrTrayChangePlaces(sNames, id);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateErrTrayChangePlaces(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateErrTrayChangePlaces(" + id + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateErrTrayChangePlaces(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateErrTrayChangePlaces(" + id + ")调用失败：" + ee.Message);
            }

            return data;
        }

        /// <summary>
        /// 异常排出
        /// </summary>
        /// <param name="id">库位的ID</param>
        /// <returns></returns>
        public static WarehouseSrv.MsgRsp UpdateErrTrayDischarge(int id)
        {
            WarehouseSrv.MsgRsp data = null;
            try
            {
                if (warehouseClient != null)
                {
                    data = warehouseClient.UpdateErrTrayDischarge(sNames, id);

                    if (!data.result)
                    {
                        PublicClass.WriteLog2DB("CallWCSClass.UpdateErrTrayDischarge(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                        PublicClass.WriteLog("CallWCSClass.UpdateErrTrayDischarge(" + id + ")调用失败：" + data.msg);
                    }
                }
            }
            catch (Exception ee)
            {
                PublicClass.WriteLog2DB("CallWCSClass.UpdateErrTrayDischarge(" + id + ")调用失败", PublicClass.LogContentType.Dispatcher);
                PublicClass.WriteLog("CallWCSClass.UpdateErrTrayDischarge(" + id + ")调用失败：" + ee.Message);
            }

            return data;
        }

    }
}
